package io.xccit.controller;

import io.xccit.entity.SysUser;
import io.xccit.entity.vo.SysUserVO;
import io.xccit.r.XResult;
import io.xccit.service.SysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CH_ywx
 * @version 1.0
 * @create 2024/10/13
 * <p>用户控制器</p>
 */
@RequestMapping("/user")
@RestController
public class SysUserController {
    private final SysUserService userService;
    public SysUserController(SysUserService userService) {
        this.userService = userService;
    }

    /**
     * 获取用户列表
     * @return
     */
    @GetMapping
    public XResult list(){
        List<SysUser> sysUserList = userService.list();
        List<SysUserVO> sysUserVOList = new ArrayList<>();
        for (SysUser sysUser : sysUserList) {
            SysUserVO sysUserVO = new SysUserVO();
            BeanUtils.copyProperties(sysUser,sysUserVO);
            sysUserVOList.add(sysUserVO);
        }
        return XResult.success(sysUserVOList);
    }
}
